 

import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Game extends JFrame implements KeyListener {

	/**
	 * @param args
	 */

	/**
	 * 
	 * 创建时间 2013年6月3日 现在2013年6月6日 02:40:31
	 * 
	 */
	JPanel P1 = new JPanel();
	JButton Bu1 = new JButton();
	JButton Bu2 = new JButton();
	JButton Bu3 = new JButton("提示");
	JTextField JT1 = new JTextField();
	JLabel JL2 = new JLabel();
	JLabel JL1 = new JLabel();
	final imgPanel gameP1;
	final imgPanel InfoP1;

	GameLED gameLED = new GameLED();
	GameThread gameT = new GameThread();
	GameELS ELS = new GameELS();

	public Game() {
		// this.setLayout(null);

		// 控件属性
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		Bu1.setBounds(25, 280, 90, 28);
		Bu2.setBounds(150, 280, 90, 28);
		Bu3.setBounds(250, 280, 90, 28);
		JL1.setBounds(80, 240, 90, 28);
		JL2.setBounds(100, 0, 100, 28);
		JL2.setText("123");

		JL1.setText("得分:");
		Bu1.setText("开始");
		Bu2.setText("暂停");

		P1 = (JPanel) this.getContentPane();
		P1.setLayout(null);
		gameP1 = new imgPanel();
		InfoP1 = new imgPanel();
		InfoP1.setBounds(150, 30, 140, 200);
		gameP1.setBounds(30, 30, 100, 200);

		P1.add(InfoP1);
		P1.add(gameP1);
		P1.add(Bu1);
		P1.add(Bu2);
		P1.add(JL1);
		P1.add(JL2);
		P1.add(Bu3);

		gameP1.setSize(100, 200);

		Bu1.addActionListener(new ActionListener() {
			// @Override
			public void actionPerformed(ActionEvent arg0) {
				bu1OnClick(arg0);

			}
		});

		Bu2.addActionListener(new ActionListener() {

			// @Overrides
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				bu2OnClick(e);
			}
		});

		Bu3.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				Bu3OnClick(arg0);
			}
		});

		Bu1.setFocusable(false);
		Bu2.setFocusable(false);
		this.setFocusable(true);

		addKeyListener(this);
		this.requestFocusInWindow();

		this.setBounds(100, 100, 350, 350);
		this.setTitle("Game");
		this.setVisible(true);
	}

	protected void Bu3OnClick(ActionEvent arg0) {
		// TODO Auto-generated method stub
		String str;
		str = "上下左右分别为:↑,↓,←,→\n" + "z为旋转\n" + "旁边两个键为测试\n"
				+ "因为没有加下落,所以自由发挥\n" + "";

		Help help = new Help(str);
		help.setBounds(20, 20, 300, 300);
		help.setVisible(true);
	}

	protected void bu2OnClick(ActionEvent e) {
		// TODO Auto-generated method stub
		gameT.GameRun = !gameT.GameRun;
	}

	protected void bu1OnClick(ActionEvent arg0) {
		// TODO Auto-generated method stub

		gameT.start();

		gameT.ELS.randNextBox();
		gameT.ELS.randBox();
		// gameT.key = 88;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Game();
	}

	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
		this.setTitle(String.valueOf(arg0.getKeyCode()));
		gameT.key = arg0.getKeyCode();
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		gameT.keyB = arg0.getKeyCode();
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	class imgPanel extends JPanel {
		Image imga;

		public void loadimage(String file) {
			imga = getToolkit().getImage(file);
			this.repaint();
		}

		public void loadimage(Image img) {
			imga = img;
			this.repaint();
		}

		public void paint(Graphics g) {
			g.drawImage(imga, 0, 0, this);
		}
	}

	class GameThread extends Thread {
		boolean GameRun;
		boolean ThreadRun;
		GameELS ELS = new GameELS();
		int key;
		int keyB;
		public int GameFPS;
		public int GameFPSa;
		public long TimeA;
		public long keyTimeA;

		public GameThread() {

		}

		public void status() {
			if (System.currentTimeMillis() - TimeA > 1000) {
				GameFPS = GameFPSa;
				GameFPSa = 0;
				TimeA = System.currentTimeMillis();
			}
			JL2.setText("帧率:" + String.valueOf(GameFPS));
		}

		public void keyEvent(long time) {
			if (this.key == this.ELS.keyA) {
				ELS.keyDown(key);
				key = 0;
			}
			if (this.key == this.ELS.keyDown) {
				if (System.currentTimeMillis() - keyTimeA > time) {
					keyTimeA = System.currentTimeMillis();
					if (keyB != key)
						this.ELS.keyDown(key);
					else {
						key = 0;
						keyB = 0;
					}
				}
			} else {
				ELS.keyDown(key);
				key = 0;
			}
		}

		public void run() {
			ThreadRun = true;
			// GameFPS=0;
			while (ThreadRun) {
				ThreadRun = false;
				GameRun = true;
				while (GameRun) {

					GameFPSa++;

					// this.ELS.keyDown(key);
					this.ELS.setXX(200);
					// this.ELS.keyDown(key);
					ELS.getELSLED(); // //必须要下这个,否则会空格
					this.keyEvent(50);
					//
					gameP1.loadimage(ELS.getELSLED());
					// this.ELS.keyDown(key);
					// ELS.getELSLED(); //必须要下这个,否则会空格
					gameP1.paint(gameP1.getGraphics());
					InfoP1.loadimage(ELS.getInfoImage());
					InfoP1.paint(InfoP1.getGraphics());
					status();

					try {
						Thread.sleep(25);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}

	class GameELS extends GameLED {
		public char BoxC;
		public char nextBoxC;

		public byte[][] BoxByte = new byte[4][4];
		public byte[][] nextBoxByte = new byte[4][4];

		public byte[][] ELSData = new byte[10][20];

		public int BoxXY[] = new int[2];

		public Random rand = new Random();

		public int Boxturn;

		public int GameMark;

		public long TimeA;
		public long XXTimeA;

		public GameInfo ELSInfo = new GameInfo();

		public GameELS() {
			XXTimeA = System.currentTimeMillis();
		}

		public void setXX(int time) {
			if (System.currentTimeMillis() - XXTimeA > time) {
				this.BoxDown();
				XXTimeA = System.currentTimeMillis();
			}
		}

		public void CS1() {
			int X, Y;
			for (Y = 0; Y < 20; Y++) {
				ELSData[7][Y] = 1;
				ELSData[1][Y] = 1;
			}
			Boxturn = 1;
			ELSData[1][3] = 0;
			ELSData[1][2] = 0;
			BoxXY[0] = 2;
		}

		public Image getInfoImage() {
			// ELSInfo.setMark(this.GameMark);
			ELSInfo.setGameInfo(this.GameMark, this.nextBoxC);
			return ELSInfo.MapA;
		}

		public void setKey(int C) {
			switch (C) {
			case keyLeft:
				key[0] = 1;
				break;
			case keyUp:
				key[0] = 1 << 1;
				break;
			case keyRight:
				key[0] = 1 << 2;
				break;
			case keyDown:
				key[0] = 1 << 3;
				break;
			case keyA:
				key[1] = 1;
				break;
			case keyB:
				key[1] = 1 << 1;
				break;
			case keyC:
				key[1] = 1 << 2;
				break;
			}
		}

		public void keyDown(int C) {
			setKey(C);
			switch (this.key[0]) {
			case 1:
				BoxLeft();
				break;
			case 1 << 2:
				BoxRight();
				break;
			case 1 << 3:
				BoxDown();
				break;
			case 1 << 1:
				BoxUp();
				break;
			default:
				break;
			}
			switch (this.key[1]) {
			case 1:
				Boxturn++;
				switch (this.BoxC) {
				case 'O':
					Boxturn = 0;
					break;
				case 'L':
					if (Boxturn > 3)
						Boxturn = 0;
					break;
				case 'J':
					if (Boxturn > 3)
						Boxturn = 0;
					break;
				case 'Z':
					if (Boxturn > 1)
						Boxturn = 0;
					break;
				case 'S':
					if (Boxturn > 1)
						Boxturn = 0;
					break;
				case 'I':
					if (Boxturn > 1)
						Boxturn = 0;
					break;
				case 'T':
					if (Boxturn > 3)
						Boxturn = 0;
					break;
				default:
					break;
				}
				break;
			case 1 << 1:
				this.setBoxAB();
				this.randNextBox();
				BoxXY[1] = 0;
				break;
			// case 1<<2:this.randBox();Boxturn=0;break;
			default:
				break;
			}

			this.key[0] = 0;
			this.key[1] = 0;
		}

		public void BoxA() {
			BoxByte = turnBox(BoxByte);
		}

		public byte[][] turnBox(byte[][] Box) {
			byte B[][] = new byte[4][4];
			int X, Y;
			for (Y = 0; Y < 4; Y++)
				for (X = 0; X < 4; X++) {
					B[3 - Y][X] = Box[X][Y];
				}
			return B;
		}

		public void BoxUp() {
			int X, Y;
			int Xa, Ya;
			boolean B;
			X = BoxXY[0];
			Y = BoxXY[1];
			B = true;
			for (Ya = 0; Ya < 4; Ya++)
				for (Xa = 0; Xa < 4; Xa++) {
					// }
					if (BoxByte[Xa][Ya] != 0) {
						if (Y + Ya - 1 < 0) {
							B = false;
							break;
						}
						if (ELSData[X + Xa][Y + Ya - 1] != 0)
							B = false;
					}
				}
			if (B)
				BoxXY[1]--;
		}

		public void BoxDown() {
			int X, Y;
			int Xa, Ya;
			boolean B;
			boolean Yxun;
			X = BoxXY[0];
			Y = BoxXY[1];
			B = true;
			Yxun = true;
			for (Ya = 0; Ya < 4; Ya++)
				for (Xa = 0; Xa < 4; Xa++) {
					// }
					if (BoxByte[Xa][Ya] != 0) {
						// if((X+Xa>9)||(X+Xa<0)){B=false;break;}
						/*
						 * if( (Y+Ya+1>19)|| (ELSData[X+Xa][Y+Ya+1]!=0)){
						 * B=false; if(Yxun){
						 * this.setBoxAB();this.randNextBox();BoxXY[1]=0;}
						 * Yxun=false;}
						 */
						if (Y + Ya + 1 > 19) {
							B = false;
							if (Yxun) {
								this.setBoxAB();
								this.randNextBox();
								BoxXY[1] = 0;
							}
							Yxun = false;
							break;
						}
						if ((X + Xa < 0) || (X + Xa > 9)) {
							B = false;
							break;
						}
						if (ELSData[X + Xa][Y + Ya + 1] != 0) {
							B = false;
							if (Yxun) {
								this.setBoxAB();
								this.randNextBox();
								BoxXY[1] = 0;
							}
							Yxun = false;
						}
					}
				}
			if (B)
				BoxXY[1]++;
		}

		public void BoxRight() {
			int X, Y;
			int Xa, Ya;
			boolean B;
			X = BoxXY[0];
			Y = BoxXY[1];
			B = true;
			for (Ya = 0; Ya < 4; Ya++)
				for (Xa = 0; Xa < 4; Xa++) {
					// }
					if (BoxByte[Xa][Ya] != 0) {
						if ((X + Xa + 1 > 9) || (X + Xa + 1 < 0)) {
							B = false;
							break;
						}
						if (ELSData[X + Xa + 1][Y + Ya] != 0)
							B = false;
					}
				}
			if (B)
				BoxXY[0]++;
		}

		public void BoxLeft() {
			int X, Y;
			int Xa, Ya;
			boolean B;
			X = BoxXY[0];
			Y = BoxXY[1];
			B = true;
			for (Ya = 0; Ya < 4; Ya++)
				for (Xa = 0; Xa < 4; Xa++)
					if (BoxByte[Xa][Ya] != 0) {
						// if(X+Xa==0)break;
						if (X + Xa - 1 < 0) {
							B = false;
							break;
						}
						if (ELSData[X + Xa - 1][Y + Ya] != 0)
							B = false;
					}
			if (B)
				BoxXY[0]--;
		}

		public void randBox() {
			int r;
			r = rand.nextInt(6);
			switch (r) {
			case 0:
				this.setBox('Z');
				break;
			case 1:
				this.setBox('S');
				break;
			case 2:
				this.setBox('I');
				break;
			case 3:
				this.setBox('T');
				break;
			case 4:
				this.setBox('L');
				break;
			case 5:
				this.setBox('O');
				break;
			case 6:
				this.setBox('J');
				break;
			default:
				return;
			}
		}

		public void randNextBox() {
			int r;
			this.BoxC = this.nextBoxC;
			setBox(this.BoxC);
			Boxturn = 0;
			r = rand.nextInt(6);
			switch (r) {
			case 0:
				this.nextBoxC = 'Z';
				break;
			case 1:
				this.nextBoxC = 'S';
				break;
			case 2:
				this.nextBoxC = 'I';
				break;
			case 3:
				this.nextBoxC = 'T';
				break;
			case 4:
				this.nextBoxC = 'L';
				break;
			case 5:
				this.nextBoxC = 'O';
				break;
			case 6:
				this.nextBoxC = 'J';
				break;
			default:
				return;
			}
			// setBox(this.nextBoxC);
		}

		public Image getELSLED() {
			int X, Y;
			this.setbackLED(false);
			for (Y = 0; Y < 20; Y++)
				for (X = 0; X < 10; X++)
					if (ELSData[X][Y] != 0)
						this.setLED(X, Y);

			setBox(this.BoxC);
			int i;
			for (i = 0; i < Boxturn; i++) {
				this.BoxByte = turnBox(this.BoxByte);
				// if ()break;
			}
			BoxturnB();
			for (Y = 0; Y < 4; Y++)
				for (X = 0; X < 4; X++)
					if (BoxByte[X][Y] != 0)
						this.setLED(BoxXY[0] + X, BoxXY[1] + Y);
			return this.getLEDImage();
		}

		public void setBoxAB() {
			int X, Y;
			for (Y = 0; Y < 20; Y++)
				for (X = 0; X < 10; X++) {
					this.ELSData[X][Y] = this.getLED(X, Y);
				}
			cutX();
			// this.randBox();
		}

		public void cutYX(int Y) {
			int X;
			int Ya;
			for (Ya = Y; Ya >= 0; Ya--) {
				for (X = 0; X < 10; X++) {
					if (Ya - 1 < 0) {
						this.ELSData[X][Ya] = 0;
					} else
						this.ELSData[X][Ya] = this.ELSData[X][Ya - 1];
				}
			}
		}

		public void cutX() {
			int X, Y;
			boolean B;
			int M;
			M = 0;
			byte[] BX = new byte[20];
			for (Y = 0; Y < 20; Y++) {
				B = true;
				for (X = 0; X < 10; X++) {
					if (this.ELSData[X][Y] == 0)
						B = false;
				}
				if (B)
					BX[Y] = 1;
			}
			for (Y = 0; Y < 20; Y++) {
				if (BX[Y] != 0) {
					M++;
					this.GameMark += M * 100;
					cutYX(Y);
				}
			}
		}

		// 非标准

		public boolean BoxturnBa(int Xb, int Yb) {
			int X, Y;
			X = Xb;
			Y = Yb;
			int Xa, Ya;
			boolean B = true;
			for (Ya = 0; Ya < 4; Ya++)
				for (Xa = 0; Xa < 4; Xa++) {
					if (BoxByte[Xa][Ya] != 0) {
						if ((X + Xa < 0) || (X + Xa > 9) || Y + Ya > 19) {
							B = false;
							break;
						}
						if (ELSData[X + Xa][Y + Ya] != 0)
							B = false;
					}
				}
			return B;
		}

		// 非标准
		public boolean BoxturnB() {
			int X, Y;
			X = BoxXY[0];
			Y = BoxXY[1];
			int Xa, Ya;
			boolean B = true;
			for (Ya = 0; Ya < 4; Ya++)
				for (Xa = 0; Xa < 4; Xa++) {
					if (BoxByte[Xa][Ya] != 0) {
						if ((X + Xa < 0) || (X + Xa > 9) || (Y + Ya > 19)) {
							B = false;
							break;
						}
						// if (X+Xa>9){B=false;break;}
						if (ELSData[X + Xa][Y + Ya] != 0)
							B = false;
					}
				}

			if (!B) {
				X++;
				if (!BoxturnBa(X, Y)) {
					X -= 2;

					if (!BoxturnBa(X, Y)) {
						// if(this.BoxC=='I')if(Boxturn<1)Boxturn=1;
						if (this.BoxC == 'I') {
							X--;
							if (!BoxturnBa(X, Y)) {
								if (Boxturn == 0)
									Boxturn = 2;
								Boxturn--;
							} else
								BoxXY[0] = X;
						} else
							Boxturn--;
					} else
						BoxXY[0] = X;
					if (Boxturn < 0)
						Boxturn = 1;
					this.BoxByte = this.getBoxbyte(this.BoxC);
					int i;
					for (i = 0; i < Boxturn; i++) {
						this.BoxByte = turnBox(this.BoxByte);
						// if ()break;
					}

				} else
					BoxXY[0] = X;
			}
			;
			return B;
			// int i;
			// for(i=0;i<Boxturn;i++)
			// this.BoxByte = turnBox(this.BoxByte);
		}

		public void setBox(char Z) {
			this.BoxC = Z;
			this.BoxByte = getBoxbyte(Z);
		}

		public byte[][] getBoxbyte(char Z) {
			switch (Z) {
			case 'I':
				return getGameTTI();
			case 'L':
				return getGameTTL();
			case 'T':
				return getGameTTT();
			case 'J':
				return getGameTTJ();
			case 'O':
				return getGameTTO();
			case 'S':
				return getGameTTS();
			case 'Z':
				return getGameTTZ();
			default:
				return new byte[4][4];
			}
		}

		public byte[][] getGameTTL() // 字母L
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 3; i++)
				Data[i][1] = 1;
			Data[2][0] = 1;
			return Data;
		}

		public byte[][] getGameTTO() {
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 2; i++) {
				Data[i][1] = 1;
				Data[i][2] = 1;
			}
			return Data;
		}

		public byte[][] getGameTTT() {
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 3; i++) {
				Data[1][i] = 1;
			}
			Data[0][1] = 1;
			return Data;
		}

		public byte[][] getGameTTS() // S
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 1; i < 3; i++) {
				Data[i][1] = 1;
				Data[i - 1][2] = 1;
			}
			return Data;
		}

		public byte[][] getGameTTZ() // 字母Z
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 2; i++) {
				Data[i][1] = 1;
				Data[i + 1][2] = 1;
			}
			return Data;
		}

		public byte[][] getGameTTJ() // 字母J
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 3; i++) {
				Data[i][1] = 1;
			}
			Data[0][0] = 1;
			return Data;
		}

		public byte[][] getGameTTI() // 字母I
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 4; i++)
				Data[i][2] = 1;
			return Data;
		}

	}

	// 帮助
	class Help extends JFrame {
		JTextField JTa = new JTextField();
		TextArea T1 = new TextArea();
		String Text;

		public Help() {
			// JTa.setBounds(10, 10, 300, 300);
			T1.setBounds(10, 10, 300, 300);
			this.add(JTa);
		}

		public Help(String s) {
			Text = s;
			T1.setBounds(10, 10, 300, 300);
			T1.setText(s);
			this.add(T1);
		}
	}

	class GameLED {
		byte[] LEDdata = new byte[200];
		byte[][] LEDXY = new byte[10][20];
		byte[] key = new byte[2];
		Image LED;
		Image LEDA;
		Graphics LEDG;
		Graphics LEDAG;

		final int keyLeft = 37;
		final int keyUp = 38;
		final int keyRight = 39;
		final int keyDown = 40;

		final int keyA = 90;
		final int keyB = 88;
		final int keyC = 67;

		public GameLED() {
			LED = nullImage(101, 201);
			LEDA = nullImage(10, 10);
			LEDG = LED.getGraphics();
			LEDG.drawRect(1, 1, 100, 200);
			LEDG.fillRect(1, 1, 98, 198);

			LEDAG = LEDA.getGraphics();

			// LEDAG.fillRect(0, 0, 10, 10);
			LEDAG.setColor(Color.white);
			LEDAG.drawRect(1, 1, 7, 7);
			// 配色方案1
			//
			// GameLEDB();
			// GameLEDA(2);
			// setColor(Color.green);

			for (int X = 0; X < 10; X++)
				for (int Y = 0; Y < 20; Y++)
					LEDXY[X][Y] = (byte) (X + (Y * 10));
		}

		// 配色方案
		public void GameLEDB() {
			Color c;
			LEDAG.setColor(Color.blue);
			LEDAG.fillRect(0, 0, 10, 10);
			LEDAG.setColor(Color.WHITE);
			LEDAG.drawLine(2, 0, 10, 10 - 2);
			LEDAG.drawLine(1, 0, 10, 10 - 1);
			LEDAG.drawLine(0, 0, 10, 10);
			LEDAG.drawLine(0, 1, 10 - 1, 10);
		}

		// 配色方案
		public void GameLEDA(int x) {
			switch (x) {
			case 1:
				LEDAG.setColor(Color.GREEN);
				break;
			case 2:
				LEDAG.setColor(Color.BLUE);
				break;
			default:
				break;
			}
			LEDAG.drawRect(3, 3, 4, 4);
		}

		// 配色方案
		public void setColor(Color c) {
			LEDAG.setColor(c);
			LEDAG.drawRect(3, 3, 4, 4);
		}

		public Image nullImage(int X, int Y) {
			Image B;
			B = new java.awt.image.BufferedImage(X, Y,
					BufferedImage.TYPE_INT_RGB);
			return B;
		}

		public void addImage(int X, int Y, Graphics G) {
			G.drawImage(LEDA, X * 10, Y * 10, null);
		}

		public void setLED(int X, int Y, boolean B) {
			if (B)
				LEDdata[getLEDxy(X, Y)] = 1;
			else
				LEDdata[getLEDxy(X, Y)] = 0;
		}

		public void setLED(int X, int Y) {
			if ((getLEDxy(X, Y) > 199) || (getLEDxy(X, Y) < 0))
				return;
			LEDdata[getLEDxy(X, Y)] = 1;
		}

		public byte getLED(int X, int Y) {
			return LEDdata[getLEDxy(X, Y)];
		}

		public void setbackLED(boolean b) {
			if (b)
				for (int X = 0; X < 10; X++)
					for (int Y = 0; Y < 20; Y++)
						LEDdata[getLEDxy(X, Y)] = 1;
			else
				LEDdata = new byte[200];
		}

		public Image getLEDImage() {
			paint();
			return LED;
		}

		int getLEDxy(int X, int Y) {
			return X + Y * 10;
		}

		public void paint() {
			LED = nullImage(LED.getWidth(null), LED.getHeight(null));
			LEDG = LED.getGraphics();
			LEDG.drawRect(1, 1, 100, 200);
			LEDG.fillRect(1, 1, 98, 198);
			int i;
			int X, Y;
			for (i = 0; i < LEDdata.length; i++)
				if (LEDdata[i] != 0) {
					X = i % 10;
					Y = i / 10;
					addImage(X, Y, LEDG);
				}
		}
	}

	class GameInfo {
		public Image MarkImgA;
		public Image TileMapA;
		public Image MapA;
		public Graphics MapAG;
		public Graphics MarkImgAG;
		public Graphics TileMapAG;
		public int GameMark;

		public Image NumImage;
		Graphics NumImageG;

		// final byte NumLen0 = 119;
		// final byte NumLen1 = 68;
		// final byte NumLen2 = 62;
		// final byte NumLen3 = 110;
		// final byte NumLen4 = 77;
		// final byte NumLen5 = 107;
		// final byte NumLen6 = 123;
		// final byte NumLen7 = 70;
		// final byte NumLen8 = 127;
		// final byte NumLen9 = 111;

		final byte NumLen[] = { 119, 68, 62, 110, 77, 107, 123, 70, 127, 111 };

		private Image TileB;
		private Image TileA;
		Graphics TileBG;
		Graphics TileAG;

		public GameInfo() {
			MarkImgA = new BufferedImage(300, 40, BufferedImage.TYPE_INT_RGB);
			TileMapA = new BufferedImage(40, 40, BufferedImage.TYPE_INT_RGB);
			MapA = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
			NumImage = new BufferedImage(12, 22, BufferedImage.TYPE_INT_RGB);

			TileB = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
			TileA = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
			TileBG = TileB.getGraphics();
			TileBG.fillRect(0, 0, 10, 10);
			TileBG.setColor(Color.RED);
			TileBG.drawRect(1, 1, 7, 7);

			TileAG = TileA.getGraphics();
			TileAG.drawRect(1, 1, 7, 7);

			NumImageG = NumImage.getGraphics();
			MarkImgAG = MarkImgA.getGraphics();
			TileMapAG = TileMapA.getGraphics();
			MapAG = MapA.getGraphics();

			MarkImgAG.fillRect(0, 0, MarkImgA.getWidth(null),
					MarkImgA.getHeight(null));

			NumImageG.fillRect(0, 0, NumImage.getWidth(null),
					NumImage.getHeight(null));
			NumImageG.setColor(Color.BLACK);
		}

		public void setMark(int mark) {
			GameMark = mark;
			int i;
			int X, Y;
			int index;
			Y = 10;
			for (i = 0; i < 10; i++) {
				X = (10 - i) * 12;
				index = mark % 10;
				setMarkXY(X, Y, NumLen[index]);
				mark /= 10;
			}
		}

		public Image newImage(int X, int Y) {
			Image B;
			B = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB);
			return B;
		}

		public void setMarkXY(int X, int Y, byte Z) // 8
		{
			int i;
			Image B;
			Graphics G;
			B = newImage(12, 22);
			G = B.getGraphics();
			G.fillRect(0, 0, B.getWidth(null), B.getHeight(null));
			G.setColor(Color.BLACK);
			for (i = 0; i < 8; i++)
				if (((Z >> i) & 1) != 0)
					switch (i) {
					case 0:
						G.drawLine(1, 2, 1, 10);
						break;
					case 1:
						G.drawLine(2, 1, 10, 1);
						break;
					case 2:
						G.drawLine(11, 2, 11, 10);
						break;

					case 3:
						G.drawLine(2, 11, 10, 11);
						break;

					case 4:
						G.drawLine(1, 12, 1, 20);
						break;
					case 5:
						G.drawLine(2, 21, 10, 21);
						break;
					case 6:
						G.drawLine(11, 12, 11, 20);
						break;
					default:
						break;
					}
			MarkImgAG.drawImage(B, X, Y, null);
		}

		public void setGameInfo(int mark, char NextTile) {
			setMark(mark);
			TileMapA = this.getCharImage(NextTile);
			MapAG.drawImage(MarkImgA, 0, 10, null);
			MapAG.drawImage(TileMapA, 20, 50, null);
		}

		public Image getCharImage(char Z) {
			Image B;
			Graphics G;
			byte[][] C;
			B = nullImage(41, 41);
			G = B.getGraphics();
			C = getGameTT(Z);
			int X, Y;
			for (Y = 0; Y < 4; Y++)
				for (X = 0; X < 4; X++) {
					addbackTile2Image(X * 10, Y * 10, G);
					if (C[X][Y] != 0)
						addTile2Image(X * 10, Y * 10, G);
				}
			return B;
		}

		public void addTile2Image(int X, int Y, Graphics G) {
			// G.setColor(Color.BLACK);
			G.drawImage(TileA, X, Y, null);
		}

		public void addbackTile2Image(int X, int Y, Graphics G) {
			G.drawImage(TileB, X, Y, null);
		}

		public byte[][] getGameTT(char Z) {
			switch (Z) {
			case 'I':
				return getGameTTI();
			case 'L':
				return getGameTTL();
			case 'T':
				return getGameTTT();
			case 'J':
				return getGameTTJ();
			case 'O':
				return getGameTTO();
			case 'S':
				return getGameTTS();
			case 'Z':
				return getGameTTZ();
			default:
				return new byte[4][4];
			}
		}

		public byte[][] getGameTTL() // 字母L
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 3; i++)
				Data[i][1] = 1;
			Data[2][0] = 1;
			return Data;
		}

		public byte[][] getGameTTO() {
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 2; i++) {
				Data[i][1] = 1;
				Data[i][2] = 1;
			}
			return Data;
		}

		public byte[][] getGameTTT() {
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 3; i++) {
				Data[1][i] = 1;
			}
			Data[0][1] = 1;
			return Data;
		}

		public byte[][] getGameTTS() // S
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 1; i < 3; i++) {
				Data[i][1] = 1;
				Data[i - 1][2] = 1;
			}
			return Data;
		}

		public byte[][] getGameTTZ() // 字母Z
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 2; i++) {
				Data[i][1] = 1;
				Data[i + 1][2] = 1;
			}
			return Data;
		}

		public byte[][] getGameTTJ() // 字母J
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 3; i++) {
				Data[i][1] = 1;
			}
			Data[0][0] = 1;
			return Data;
		}

		public byte[][] getGameTTI() // 字母I
		{
			byte Data[][] = new byte[4][4];
			int i;
			for (i = 0; i < 4; i++)
				Data[i][2] = 1;
			return Data;
		}

		public Image nullImage(int X, int Y) {
			Image imgA;
			Graphics imgG;
			imgA = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB);
			imgG = imgA.getGraphics();
			imgG.drawRect(1, 1, 100, 200);
			imgG.fillRect(1, 1, 98, 198);
			return imgA;
		}
	}
}
